module ApplicationHelper
  include WillPaginate::ViewHelpers

  def will_paginate_locale(collection, options = {})
    will_paginate(collection, options.merge(:previous_label => I18n.t("pagination.previous"), :next_label => I18n.t("pagination.next")))
  end

  def get_availiable form_name, section_name, field_name
    SITE["forms"][form_name]["sections"].each do |section|
      if section["name"] == section_name
        section["fields"].each do |field|
          if field["name"] == field_name
            return field["availiable"]
          end
        end
      end
    end
  end

  def get_formatted_date date
    "#{date.day} #{I18n.t("date.month_names")[date.month]}, #{date.year}"
  end
  
  def round_corners(hash, &block)
    content = content_tag(:div,
      content_tag(:div, nil, :class => "round#{hash[:classname].capitalize} roundTopLeft #{hash[:topleft]}"),
      :class => "round#{hash[:classname].capitalize} roundTopRight #{hash[:topright]}")
    content << content_tag(:div,
      content_tag(:div, capture(&block), :class => "round#{hash[:classname].capitalize} roundBottomLeft #{hash[:bottomleft]}"),
      :class => "round#{hash[:classname].capitalize} roundBottomRight #{hash[:bottomright]}")
    content_tag(:div, content, :class => hash[:classname])
  end

  def quantity(hash, &block)
    content = content_tag(:div, nil, :class => hash[:quantity_decrease])
    content << capture(&block)
    content << content_tag(:div, nil, :class => hash[:quantity_increase])
  end
  
  def get_select_value entity, form_name, method_name
    value = entity.send method_name
    if value
      return I18n.t("#{form_name}.#{method_name}.#{value}")
    else
      return "mistake"
    end
  end
end
